<?php
error_reporting(E_ALL);
ini_set('display_errors','On');

$timezone = "Asia/Saigon";
if(function_exists('date_default_timezone_set'))
    date_default_timezone_set($timezone);

session_start();

require_once 'config/config.php';
require_once 'plugin/Smarty/Smarty.class.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'Util'          . DIRECTORY_SEPARATOR . 'SEO.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'Util'          . DIRECTORY_SEPARATOR . 'Pager.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'Util'          . DIRECTORY_SEPARATOR . 'Tool.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'Context'       . DIRECTORY_SEPARATOR . 'BaseContext.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'ServiceResult' . DIRECTORY_SEPARATOR . 'ServiceResult.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'Service'       . DIRECTORY_SEPARATOR . 'GameService.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'Service'       . DIRECTORY_SEPARATOR . 'GameCategoryService.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'Service'       . DIRECTORY_SEPARATOR . 'GamePromotionService.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'Service'       . DIRECTORY_SEPARATOR . 'AppService.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'Service'       . DIRECTORY_SEPARATOR . 'AppLinkService.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'Service'       . DIRECTORY_SEPARATOR . 'AppMessageService.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'Service'       . DIRECTORY_SEPARATOR . 'UserService.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'Service'       . DIRECTORY_SEPARATOR . 'GameTagService.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'Service'       . DIRECTORY_SEPARATOR . 'DeviceService.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'Service'       . DIRECTORY_SEPARATOR . 'GameMessageService.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'Service'       . DIRECTORY_SEPARATOR . 'TelcoPromotionService.php';
try {

    $url        = $_SERVER['REQUEST_URI'];

    $urlArr     = explode('/', $url);

    $controller = isset($_GET['controller']) ? $_GET['controller'] : 'index';
    $action     = isset($_GET['action']) ? $_GET['action'] : 'index';

    $smarty = new Smarty();

    $smarty->config_dir  = WEB_BASE_DIR . DIRECTORY_SEPARATOR . "conf/";
    $smarty->compile_dir = WEB_BASE_DIR . DIRECTORY_SEPARATOR . "cache/";
    $smarty->template_dir = WEB_TEMPLATE_DIR;
    $smarty->assign('WEB_BASE_URL', WEB_BASE_URL);

    if(!isset($_COOKIE['token']) && $controller != 'user' && $action != 'login')
    {

        if (!isset($_SESSION['time_out']) && $controller != 'user' && $action != 'login')
        {

            header("location:".WEB_BASE_URL."/index.php?controller=user&action=login");
        }
    }
    else
    {
        if (isset($_COOKIE['token'])) {
            setcookie("token", "value", time()+60*60*24*100, "/");
        }
        require_once WEB_APP_DIR . DIRECTORY_SEPARATOR . ucfirst($controller) . DIRECTORY_SEPARATOR . 'controller' . DIRECTORY_SEPARATOR . ucfirst($controller) . 'Controller.php';
        $controllerClass    = ucfirst($controller) . 'Controller';

        $actionFunction     = $action . 'action';
        $obj                = new $controllerClass;
        $obj->main($smarty);
        call_user_func(array($obj, $actionFunction));
    }

} catch (Exception $e) {

}
exit;

?>